package com.yun.zhong.fu.usercenter.rocketmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.stereotype.Service;

/**
 * @Author RenPu
 * @Date 2021/1/4 17:20
 * @Version 1.0
 * @Description: rocketmq的消费者的编写
 **/
@Service
@Slf4j
public class RocketMqConsumer {

    @StreamListener(Sink.INPUT)
    public void recevice(String messageBody) {
        log.info("通过stream收到了消息：messageBody ={}", messageBody);
        //模拟异常的出现
        //throw new IllegalArgumentException("抛异常");
    }


    /**
     * 编写消息消费者出现异常的解决方法
     * @param message
     */
    @StreamListener("errorChannel")
    public void error(Message<?> message) {
        ErrorMessage errorMessage = (ErrorMessage) message;
        log.warn("发生异常,errorMessage = {}", errorMessage);


    }




}
